/****************************************************
          File Name:rename.c
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Mon Dec  8 19:49:02 2014
*****************************************************/

#include "dir.h"

int main(int argc, char *argv[])
{
    int res;
    char cmd[256];

    if(argc < 3)
    {
        fprintf(stderr, "%s oldpath newpath\n", argv[0]);
        exit(1);
    }

    res = rename(argv[1], argv[2]);
    if(res == -1)
        err("rename");

    printf("show result:\n");
    snprintf(cmd, 256, "ls | grep %s", argv[2]);
    system(cmd);

    sleep(3);
    res = rename(argv[2],argv[1]);
    if(res == -1)
        err("undo");
    printf("undo changes done!\n");

    return 0;
}
